<?php
class Application_Acl_Setup
{
    /**
     * @var Zend_Acl
     */
    protected $_acl;
 
    public function __construct()
    {
        $this->_acl = new Zend_Acl();
        $this->_initialize();
    }
 
    protected function _initialize()
    {
        $this->_setupRoles();
        $this->_setupResources();
        $this->_setupPrivileges();
        $this->_saveAcl();
    }
 
    protected function _setupRoles()
    {
        $this->_acl->addRole( new Zend_Acl_Role('usuario') );
        $this->_acl->addRole( new Zend_Acl_Role('coordenador'), 'usuario');
        $this->_acl->addRole( new Zend_Acl_Role('dirigente'), 	'coordenador');
        $this->_acl->addRole( new Zend_Acl_Role('admin'), 		'dirigente');
    }
 
    protected function _setupResources()
    {
        $this->_acl->addResource( new Zend_Acl_Resource('index') );
        $this->_acl->addResource( new Zend_Acl_Resource('error') );
        $this->_acl->addResource( new Zend_Acl_Resource('usuario') );
        $this->_acl->addResource( new Zend_Acl_Resource('paroquia') );
        $this->_acl->addResource( new Zend_Acl_Resource('encontro') );
    }
 
    protected function _setupPrivileges()
    {
        $this->_acl->allow( 'usuario', 'index', array('index', 'login', 'logout') )
                   ->allow( 'usuario', 'error', array('error', 'forbidden') );
        
//         $this->_acl->allow( 'coordenador', 'usuario', array('index') );
        
        $this->_acl->allow( 'dirigente', 'usuario', array('index','adicionar','editar','delete','get-encontros-paroquia','get-equipes-encontro') )
        		   ->allow( 'dirigente', 'paroquia', array('minha-paroquia') )
        		   ->allow( 'dirigente', 'encontro', array('index', 'adicionar', 'editar', 'delete') );
        
        $this->_acl->allow( 'admin', 'paroquia', array('index', 'adicionar', 'editar', 'delete') );
    }
 
    protected function _saveAcl()
    {
        $registry = Zend_Registry::getInstance();
        $registry->set('acl', $this->_acl);
    }
}